#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Log.h"
#include "HObject.h"

//TODO Figure out a better way to initialize the static logger
helix::Log helix::HObject::logFile = helix::Log();


namespace helix
{

	HObject::HObject()
	{
		numRefs=0;						//there are currently no objects linked to this one
		//	logFile.Println("Object Created");
	}

	HObject::~HObject()
	{
		if (numRefs>1)           //if something is still referencing this object
			logFile.Error("Attempting to delete object with %d pointers to it.",numRefs);
	}

	void HObject::Print()
	{
		logFile.Println("Object initialized");
	}

	void HObject::AddRef()
	{
		numRefs++;
	}

	void HObject::SetRefs(int r)
	{
		numRefs=r;
	}

	void HObject::DeleteRef()
	{
		numRefs--;
	}

	int HObject::GetRefCount()
	{
		return numRefs;
	}

	Log HObject::Log()
	{
		return logFile;
	}

	Log HObject::logger()
	{
		return logFile;
	}

	char* HObject::toString()
	{
		char *str="Object: refs=";
		char result[10];
		result[9]='\0';
		_itoa_s(numRefs,result,10);
		return strcat(str,result);
	}

}